package br.ufrj.ppgi.infovis.mtgraph.buttons;

import org.mt4j.AbstractMTApplication;
import org.mt4j.MTApplication;
import org.mt4j.components.visibleComponents.widgets.buttons.MTImageButton;
import org.mt4j.input.inputProcessors.IGestureEventListener;
import org.mt4j.input.inputProcessors.MTGestureEvent;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapEvent;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapProcessor;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;
import org.mt4j.components.css.style.CSSStyle;
import org.mt4j.components.css.util.CSSHelper;
import org.mt4j.components.css.util.CSSStylableComponent;



import processing.core.PImage;


public class ButtonRemove {

	public ButtonRemove(){
		System.out.println("entrou");
	}

	String img_prefix= "br" +  AbstractMTApplication.separator +
			"ufrj" +  AbstractMTApplication.separator + "ppgi" + AbstractMTApplication.separator + 
			"infovis" +  AbstractMTApplication.separator + "data" +  AbstractMTApplication.separator;

	MTApplication app;
	
	public MTImageButton makeButtonRemove(MTApplication app) {
		
		this.app = app;

		PImage bt_menos_img = app.loadImage(img_prefix + "TrashIconEmpty.png");
		final MTImageButton remove_bt = new MTImageButton(app, bt_menos_img);
		remove_bt.setName("ButtonRemove");
		remove_bt.setNoStroke(true);		
		remove_bt.setPositionGlobal(new Vector3D(app.getWidth()-40,app.getHeight()-40,0));
		remove_bt.setSizeXYGlobal(50,50);	
		
		final MTColor color = remove_bt.getFillColor();
		
		
		remove_bt.addGestureListener(TapProcessor.class, new IGestureEventListener() {
			int i=0;
			boolean ligado = true;
			@Override		
			public boolean processGestureEvent(MTGestureEvent ge) {
				
				System.out.println("clicou?");
				
				TapEvent te = (TapEvent)ge;
				switch (te.getTapID()) {
				case TapEvent.TAPPED:
					if (ligado) {
						ligado = false;						
						remove_bt.setFillColor(new MTColor(128,0,128,255,true));
						
						
					} else {
						ligado = true;						
						remove_bt.setFillColor(color);
						}
					
					i++;
					System.out.println("clicou "+i+" ligado = "+ligado);
					break;
				default:
					break;
				}
				return true;
			}

		});

		return remove_bt;

	}
}
